/**
 * 
 */
package any.tag.dao.hibernate;

import java.util.Collection;

import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import any.tag.Tag;
import any.tag.dao.TagDao;

/**
 * TODO: Doc me
 * 
 * @author keke <keke@codehaus.org>
 * @version
 * @revision $Revision:$
 */
public class HibernateTagDao extends HibernateDaoSupport implements TagDao {

    public Tag getTag(final String tagName) {
        return (Tag) getSessionFactory().getCurrentSession().createCriteria(
                Tag.class).add(Restrictions.eq("name", tagName)).setMaxResults(
                1).uniqueResult();
    }

    /*
     * (non-Javadoc)
     * 
     * @see any.tag.dao.TagDao#listAll()
     */
    public Collection<Tag> listAll() {
        return getSessionFactory().getCurrentSession()
                .createCriteria(Tag.class).list();
    }

    public void save(final Tag tag) {
        getSessionFactory().getCurrentSession().saveOrUpdate(tag);
    }

}
